package com.monkeybrother.thread.callable;

import java.util.concurrent.*;
import java.util.stream.LongStream;

public class ComputeNumThread implements Callable<Long> {
    private Long start;
    private Long end;

    public ComputeNumThread(Long start, Long end) {
        this.start = start;
        this.end = end;
    }

    @Override
    public Long call() throws Exception {
        return LongStream.range(start, end).sum();
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        99999999999999L
        ExecutorService executor = Executors.newCachedThreadPool();
        Future<Long> a1 = executor.submit(new ComputeNumThread(0L, 33333333333333L));
        Future<Long> a2 = executor.submit(new ComputeNumThread(33333333333333L, 66666666666666L));
        Future<Long> a3 = executor.submit(new ComputeNumThread(66666666666666L, 99999999999999L));
        System.out.println(a2.get() + a1.get() + a3.get());
    }
}
